﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Small
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Convert.ToString(Session["Username"]) != "")
            {
                this.Label1.Text = "Hi:" + Session["Username"] as string;
                Login2.Visible = false;

            }
            else
            {
                this.Label1.Text = Session["Username"] as string;
                Login2.Visible = true;
            }
        }

        protected void Login2_LoggedIn(object sender, EventArgs e)
        {
            Session["Username"] = this.Login2.UserName;
            Response.Redirect("Admin_Home.aspx");
        }

        protected void Login2_Authenticate(object sender, AuthenticateEventArgs e)
        {
            DataClassesDataContext db = new DataClassesDataContext();
            if (db.Users.Where(p => p.Username == this.Login2.UserName && p.Password == this.Login2.Password).Count() == 1)
            {
                e.Authenticated = true;
            }
            else
            {
                e.Authenticated = false;
            }
        }
    }
}